package junit;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import backend_package.Packet;

/**
 * 
 * @author Kyler
 *
 */
public class PacketTest {
	Packet p1;
	Packet p2;
	Packet p3;
	Packet p4;

	/**
	 * @author Kyler
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @author Kyler
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @author Kyler
	 */
	@Before
	public void setUp() throws Exception {
		Object[] oarr = {"String", 0};
		
		p1 = new Packet("Tag");
		p2 = new Packet("Tag", "Name");
		p3 = new Packet("Tag", oarr, "Name", 1);
		p4 = new Packet("Tag", oarr);
	}

	@After
	public void tearDown() throws Exception {
	}

	/**
	 * @author Kyler
	 */
	@Test
	public void testPacketStringEmpty() {
		Packet p = new Packet("");
		assertTrue(p.getUsername().isEmpty());
	}

	/**
	 * @author Kyler
	 */
	@Test
	public void testPacketStringObjectArray() {
		Packet p = new Packet("");
		p.tag = "Tag";
		assertEquals(p, p1);
	}

	/**
	 * @author Kyler
	 */
	@Test
	public void testPacketStringString() {
		Packet p = new Packet("", "");
		p.tag = "Tag";
		p.username = "Name";
		assertEquals(p, p2);
	}

	/**
	 * @author Kyler
	 */
	@Test
	public void testPacketStringObjectArrayString() {
		Packet p = new Packet("", new Object[]{});
		p.tag = "Tag";
		p.oarr = new Object[]{"String", 0};
		assertEquals(p, p4);
	}
	
	/**
	 * @author Kyler
	 */
	@Test
	public void testPacketStringObjectArrayStringInt() {
		Packet p = new Packet("", new Object[]{}, "", 0);
		p.tag = "Tag";
		p.username = "Name";
		p.oarr = new Object[]{"String", 0};
		p.whichTable = 1;
		assertEquals(p, p3);
	}
	
	/**
	 * @author Kyler
	 */
	@Test
	public void testGetTag() {
		assertEquals("Tag",p1.getTag());
	}

	/**
	 * @author Kyler
	 */
	@Test
	public void testGetUsername() {
		assertEquals("Name",p2.getUsername());
	}

	/**
	 * @author Kyler
	 */
	@Test
	public void testGetWhichTable() {
		assertEquals(1,p3.getWhichTable());
	}

	/**
	 * @author Kyler
	 */
	@Test
	public void testGet() {
		assertEquals("String",p3.get(0));
	}

}
